﻿/* 3. Write a program that compares two char arrays lexicographically (letter by letter). */

using System;

public class LexicographicallyComparisonOfCharArrays
{
    public static char[][] arrays = new char[2][];
    public static int firstLength;
    public static int secondLength;

    public static void Main()
    {
        if (DataInput())
        {
            switch (Comparison())
            {
                case '>': { Console.WriteLine("Array0 > Array1\n"); break; }
                case '<': { Console.WriteLine("Array1 > Array0\n"); break; }
                default: { Console.WriteLine("Array0 == Array1\n"); break; }
            }
        }
        else
            Console.WriteLine("The lengths of both arrays must be nonnegative integers!\n");
    }

    private static bool DataInput()
    {
        Console.Write("\nThe length of first char array: ");
        firstLength = int.Parse(Console.ReadLine());
        Console.WriteLine();

        if (0 <= firstLength)
        {
            arrays[0] = new char[firstLength];
            for (int i = 0; i < firstLength; i++)
            {
                Console.Write("Array0[{0}] = ", i);
                arrays[0][i] = char.Parse(Console.ReadLine());
            }

            if (0 < firstLength)
                Console.WriteLine();
        }
        else
            return false;

        Console.Write("The length of second char array: ");
        secondLength = int.Parse(Console.ReadLine());
        Console.WriteLine();

        if (0 <= secondLength)
        {
            arrays[1] = new char[secondLength];
            for (int i = 0; i < secondLength; i++)
            {
                Console.Write("Array1[{0}] = ", i);
                arrays[1][i] = char.Parse(Console.ReadLine());
            }

            if (0 < secondLength)
                Console.WriteLine();
        }
        else
            return false;

        return true;
    }

    public static char Comparison()
    {
        char comparison = '=';
        int minLength = firstLength;

        if (firstLength == 0)
        {
            if (secondLength > 0)
                comparison = '>';
        }
        else
        {
            if (secondLength == 0)
                comparison = '<';
            else
            {
                if (secondLength < firstLength)
                    minLength = secondLength;

                for (int i = 0; i < minLength; i++)
                {
                    if ((int)arrays[0][i] < (int)arrays[1][i])
                    {
                        comparison = '>';
                        break;
                    }
                    else if ((int)arrays[0][i] > (int)arrays[1][i])
                    {
                        comparison = '<';
                        break;
                    }
                }

                if (comparison == '=')
                {
                    if (firstLength > minLength)
                        comparison = '<';
                    else if (secondLength > minLength)
                        comparison = '>';
                }
            }
        }

        return comparison;
    }
}